package com.xpgk.mvc.warning.courseDeficiency;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.tools.ToolDateTime;
public class CourseDeficiencyController extends BaseController{
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(CourseDeficiencyController.class);

	private CourseDeficiencyService courseDeficiencyService;
	//涨称
	public void index(){
		Date date = ToolDateTime.getDate();
		Organization organ=Organization.dao.findById(getCUserOrganIds());
		setAttr("organization",organ);
		setAttr("productIds","4777c2c215b6408ab13c1eac4190ce46");
		setAttr("date",date);
		
		//	
		Code parentCode = Code.cacheGet(Code.getCode("code_yjsz"));
		List<Code> codeList = Code.cacheGetChild(parentCode.getPKValue());
		float count = 3;
		for (Code code : codeList) {
			String id =code.get(Code.column_ids);
			if(id.equals("884f99f328b44eada884d3bf40752ae0")){
				count = Float.parseFloat((String) code.get(Code.column_code));
			}
		}		
		
		
		setAttr("count",count);
		render("courseDeficiency.html");
		
	}
	/*
	 * 查询结果导出
	 */
	public void excel() throws UnsupportedEncodingException{
		String organIds = getPara("organIds");
		String organName = getPara("orgName");
		organName = new String(organName.getBytes("ISO-8859-1"), "UTF-8"); 
		String date = getPara("date");
		String productIds = getPara("productIds");
		String count = getPara("count");

		String organizationName = organIds.equals("")?"":("门店："+organName+"，");
		String dateSearch = date.equals("")?"":("日期："+date+"，");
		String search = organIds.equals("")?"":(organizationName+dateSearch);
		String excelname = "单疗程不足顾客";
		splitPage.setExport(true);
		Map<String, Object> map =splitPage.getQueryParam();
		map.put("organIds", organIds);
		map.put("date", date);
		map.put("productIds", productIds);
		map.put("count", count);
		
		paging(splitPage,CourseDeficiencySQL.CourseDeficiency_splitPageSelect,CourseDeficiencySQL.CourseDeficiency_splitPageFrom);
		List<Record> result =(List<Record>) splitPage.getList();
		render(new CourseDeficiencyXLS(result,excelname,search));
	}
	
	/**
	 * 单疗程不足顾客查询
	 */
	public void queryIncrease(){
		String json=paging(splitPage,CourseDeficiencySQL.CourseDeficiency_splitPageSelect,CourseDeficiencySQL.CourseDeficiency_splitPageFrom);
		renderJson(json);
	}
	/**
	 * 回访
	 */
	public void visit(){
		render("visit.html");
	}
	/**
	 * 查询
	 */
	public void query(){
		render("query.html");
	}
}
